// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

// 云函数入口函数
exports.main = async (event, context) => {
  try {
    const wxContext = cloud.getWXContext()
    const templateId = 'It_sBikfSOy_PgnlfbHV1J4-KfWzISkuCEs2gpdACns'
    const result = await cloud.openapi.subscribeMessage.send({
        touser: wxContext.OPENID,
        page: 'pages/blogComment/blogComment?id='+event.blogId,
        lang: 'zh_CN',
        data: {
          thing2: {
            value: event.content
          },
          name4: {
            value: event.user
          }
        },
        templateId,
        miniprogramState: 'developer'
      })
    return result
  } catch (err) {
    return err
  }
}